function [ R ] = local_min_max( data )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
    local_min = 0;
    local_max = 0;
    R = 0;
    count = 0;
    data_length = length(data);
    next_data = [0 data(1:data_length -1)];
    
    d_data = data - next_data;
    dd_data =[ d_data > 0];
    
    dd_next_data = [0 dd_data(1:data_length -1)];
    ddd_data = dd_data - dd_next_data;
    
    for i = 1 : 1 : data_length
        if ddd_data(i) == 1
            local_max = data(i);
            R = R + local_max - local_min;
            count = count + 1;
        end
        
        if ddd_data(i) == -1
            local_min = data(i);
            R = R + local_max - local_min;
            count = count + 1;
        end
    end
    R = R / count;

end

